home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / +system+ / tools / gui / bgui.lha / bgui / Examples / Source / PopButtonDemo.c < prev    next >
C/C++ Source or Header  |  2000-02-27  |  8KB  |  292 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/Gadgets/PopButton/Attic/PopButtonDemo.c,v 1.1.2.1 1999/05/31 01:42:39 mlemos Exp $
  3.  *
  4.  * PopButtonDemo.c
  5.  *
  6.  * (C) Copyright 1999 BGUI Developement team.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  *    NMC (12.12.95): Added another menu to demonstrate enabling
  12.  *            and disabling.
  13.  *
  14.  * $Log: PopButtonDemo.c,v $
  15.  * Revision 1.1.2.1  1999/05/31 01:42:39  mlemos
  16.  * Ian sources.
  17.  *
  18.  *
  19.  *
  20.  */
  21.  
  22. #include <exec/types.h>
  23. #include <libraries/bgui.h>
  24. #include <libraries/bgui_macros.h>
  25.  
  26. #include <clib/alib_protos.h>
  27.  
  28. #include <proto/exec.h>
  29. #include <proto/intuition.h>
  30. #include <proto/bgui.h>
  31. #include <proto/dos.h>
  32. #include <proto/utility.h>
  33.  
  34. /*
  35.  *    Object ID.
  36.  */
  37. #define ID_QUIT                 1
  38. #define ID_POPMENU1        2
  39. #define ID_POPMENU2        3
  40. #define ID_POPMENU3        4
  41. #define ID_POPMENU4        5    /* NMC */
  42.  
  43. /*
  44.  *    Menu entries.
  45.  */
  46. struct PopMenu Project[] = {
  47.     "New",          0, 0,
  48.     "Open...",      0, 0,
  49.     PMB_BARLABEL,    0, 0,
  50.     "Save",         0, 0,
  51.     "Save As...",   0, 0,
  52.     PMB_BARLABEL,    0, 0,
  53.     "Print",        0, 0,
  54.     "Print As...",  0, 0,
  55.     PMB_BARLABEL,    0, 0,
  56.     "About...",     0, 0,
  57.     PMB_BARLABEL,    0, 0,
  58.     "Quit",         0, 0,
  59.     NULL,        0, 0 };
  60.  
  61. struct PopMenu    Edit[] = {
  62.     "Cut",          0, 0,
  63.     "Copy",         0, 0,
  64.     "Paste",        0, 0,
  65.     PMB_BARLABEL,    0, 0,
  66.     "Erase",        0, 0,
  67.     NULL,        0, 0 };
  68.  
  69. /*
  70.  *    This menu has checkable items and mutual exclusion.
  71.  *
  72.  *    The first item will mutually-exclude the last
  73.  *    four items and any of the last four items will
  74.  *    mutually-exclude the first item.
  75.  */
  76. struct PopMenu    Exclude[] = {
  77.     "Uncheck below",        PMF_CHECKIT,                    (1<<2)|(1<<3)|(1<<4)|(1<<5),
  78.     PMB_BARLABEL,        0,                0,
  79.     "Item 1",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  80.     "Item 2",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  81.     "Item 3",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  82.     "Item 4",               PMF_CHECKIT|PMF_CHECKED,        (1<<0),
  83.     NULL,            0,                0
  84. };
  85.  
  86. /*
  87.  *    This menu has two items that enable the other
  88.  *    when selected. (NMC)
  89.  */
  90. struct PopMenu    Able[] = {
  91.     "Enable below",        0,        0,
  92.     "Enable above",        PMF_DISABLED,    0,
  93.     NULL,            0,        0
  94. };
  95.  
  96. /*
  97.  *    Library base and class base.
  98.  */
  99. struct Library *BGUIBase;
  100.  
  101. /*
  102.  *    Put up a simple requester.
  103.  */
  104. ULONG Req( struct Window *win, UBYTE *gadgets, UBYTE *body, ... )
  105. {
  106.     struct bguiRequest    req = { NULL };
  107.  
  108.     req.br_GadgetFormat    = gadgets;
  109.     req.br_TextFormat    = body;
  110.     req.br_Flags        = BREQF_CENTERWINDOW|BREQF_AUTO_ASPECT|BREQF_LOCKWINDOW|BREQF_FAST_KEYS;
  111.  
  112.     return( BGUI_RequestA( win, &req, ( ULONG * )( &body + 1 )));
  113. }
  114.  
  115. int main( int argc, char **argv )
  116. {
  117.     struct Window        *window;
  118.     Object            *WO_Window, *GO_Quit, *GO_PMB, *GO_PMB1, *GO_PMB2, *GO_PMB3; /* NMC */
  119.     ULONG             signal, rc, tmp = 0;
  120.     UBYTE            *txt;
  121.     BOOL             running = TRUE;
  122.  
  123.     /*
  124.      *    Open BGUI.
  125.      */
  126.     if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  127.             /*
  128.              *    Create the popmenu buttons.
  129.              */
  130.             GO_PMB    = BGUI_NewObject(BGUI_POPBUTTON_GADGET,
  131.                                  PMB_MenuEntries,     Project,
  132.                                  /*
  133.                                   *         Let this one activate
  134.                                   *         the About item.
  135.                                   */
  136.                                  PMB_PopPosition,     9,
  137.                                  LAB_Label,          "_Project",
  138.                                  LAB_Underscore,     '_',
  139.                                  GA_ID,         ID_POPMENU1,
  140.                                  TAG_END );
  141.  
  142.             GO_PMB1 = BGUI_NewObject(BGUI_POPBUTTON_GADGET,
  143.                                  PMB_MenuEntries,     Edit,
  144.                                  LAB_Label,          "_Edit",
  145.                                  LAB_Underscore,     '_',
  146.                                  GA_ID,         ID_POPMENU2,
  147.                                  TAG_END );
  148.  
  149.             GO_PMB2 = BGUI_NewObject(BGUI_POPBUTTON_GADGET,
  150.                                  PMB_MenuEntries,     Exclude,
  151.                                  LAB_Label,          "E_xclude",
  152.                                  LAB_Underscore,     '_',
  153.                                  GA_ID,         ID_POPMENU3,
  154.                                  TAG_END );
  155.  
  156.             GO_PMB3 = BGUI_NewObject(BGUI_POPBUTTON_GADGET,
  157.                                  PMB_MenuEntries,     Able,    /* NMC */
  158.                                  /*
  159.                                   *         Make this menu always
  160.                                   *         appear below the label
  161.                                   */
  162.                                  PMB_PopPosition,     ~0,
  163.                                  LAB_Label,          "E_nable",
  164.                                  LAB_Underscore,     '_',
  165.                                  GA_ID,         ID_POPMENU4,
  166.                                  TAG_END );
  167.             /*
  168.              *    Create the window object.
  169.              */
  170.             WO_Window = WindowObject,
  171.                 WINDOW_Title,        "PopButtonClass Demo",
  172.                 WINDOW_AutoAspect,    TRUE,
  173.                 WINDOW_SmartRefresh,    TRUE,
  174.                 WINDOW_RMBTrap,         TRUE,
  175.                 WINDOW_MasterGroup,
  176.                     VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  177.                         GROUP_BackFill,         SHINE_RASTER,
  178.                         StartMember,
  179.                             HGroupObject, Spacing( 4 ), HOffset( 6 ), VOffset( 4 ),
  180.                                 NeXTFrame,
  181.                                 FRM_BackDriPen,         FILLPEN,
  182.                                 StartMember, GO_PMB, FixMinWidth, EndMember,
  183.                                 StartMember, VertSeparator, EndMember,
  184.                                 StartMember, GO_PMB1, FixMinWidth, EndMember,
  185.                                 StartMember, VertSeparator, EndMember,
  186.                                 StartMember, GO_PMB2, FixMinWidth, EndMember,
  187.                                 StartMember, VertSeparator, EndMember,
  188.                                 StartMember, GO_PMB3, FixMinWidth, EndMember,    /* NMC */
  189.                                 StartMember, VertSeparator, EndMember,        /* NMC */
  190.                             EndObject, FixMinHeight,
  191.                         EndMember,
  192.                         StartMember,
  193.                             InfoFixed( NULL, ISEQ_C
  194.                                      "This demonstrates the usage of the \"PopButtonClass\"\n"
  195.                                      "When you click inside the above popmenu buttons a small\n"
  196.                                      "popup-menu will appear which you can choose from.\n\n"
  197.                                      "You can also key-activate the menus and browse though the\n"
  198.                                      "items using the cursor up and down keys. Return or Enter\n"
  199.                                      "acknowledges the selection and escape cancels it.",
  200.                                      NULL, 7 ),
  201.                         EndMember,
  202.                         StartMember,
  203.                             HGroupObject,
  204.                                 VarSpace( DEFAULT_WEIGHT ),
  205.                                 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  206.                                 VarSpace( DEFAULT_WEIGHT ),
  207.                             EndObject, FixMinHeight,
  208.                         EndMember,
  209.                     EndObject,
  210.             EndObject;
  211.  
  212.             /*
  213.              *    Object created OK?
  214.              */
  215.             if ( WO_Window ) {
  216.                 /*
  217.                 ** NMC: Amended to not rely on return from
  218.                 ** GadgetKey == 1 exactly. Yes, Jan, I know
  219.                 ** you know it will be 1 - you wrote it! :-)
  220.                 **/
  221.                 if (GadgetKey( WO_Window, GO_Quit,  "q" ) &&
  222.                     GadgetKey( WO_Window, GO_PMB,   "p" ) &&
  223.                     GadgetKey( WO_Window, GO_PMB1,  "e" ) &&
  224.                     GadgetKey( WO_Window, GO_PMB2,  "x" ) &&
  225.                     GadgetKey( WO_Window, GO_PMB3,  "n" )
  226.                     ) {
  227.                     if ( window = WindowOpen( WO_Window )) {
  228.                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  229.                         do {
  230.                             Wait( signal );
  231.                             while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  232.                                 switch ( rc ) {
  233.  
  234.                                     case    WMHI_CLOSEWINDOW:
  235.                                     case    ID_QUIT:
  236.                                         running = FALSE;
  237.                                         break;
  238.  
  239.                                     case    ID_POPMENU4:
  240.                                         GetAttr( PMB_MenuNumber, GO_PMB3, &tmp );
  241.                                         DoMethod( GO_PMB3, PMBM_ENABLE_ITEM, tmp ^ 1 );
  242.                                         DoMethod( GO_PMB3, PMBM_DISABLE_ITEM, tmp );
  243.                                         txt = Able[ tmp ].pm_Label;
  244.                                         goto def;
  245.  
  246.                                     case    ID_POPMENU3:
  247.                                         GetAttr( PMB_MenuNumber, GO_PMB2, &tmp );
  248.                                         txt = Exclude[ tmp ].pm_Label;
  249.                                         goto def;
  250.  
  251.                                     case    ID_POPMENU2:
  252.                                         GetAttr( PMB_MenuNumber, GO_PMB1, &tmp );
  253.                                         txt = Edit[ tmp ].pm_Label;
  254.                                         goto def;
  255.  
  256.                                     case    ID_POPMENU1:
  257.                                         GetAttr( PMB_MenuNumber, GO_PMB, &tmp );
  258.                                         switch ( tmp ) {
  259.                                             case    9:
  260.                                                 Req( window, "*OK", ISEQ_C ISEQ_B "PopButtonClass DEMO\n" ISEQ_N "(C) Copyright 1995 Jaba Development." );
  261.                                                 break;
  262.  
  263.                                             case    11:
  264.                                                 running = FALSE;
  265.                                                 break;
  266.  
  267.                                             default:
  268.                                                 txt = Project[ tmp ].pm_Label;
  269.                                                 def:
  270.                                                 Req( window, "*OK", ISEQ_C "Selected Item %ld <" ISEQ_B "%s" ISEQ_N ">", tmp, txt );
  271.                                                 break;
  272.                                         }
  273.                                         break;
  274.                                 }
  275.                             }
  276.                         } while ( running );
  277.                     }
  278.                 }
  279.                 DisposeObject( WO_Window );
  280.         }
  281.         CloseLibrary( BGUIBase );
  282.     }
  283. }
  284.  
  285. #ifdef _DCC
  286. int wbmain( struct WBStartup *wbs )
  287. {
  288.     return( main( 0, wbs ));
  289. }
  290. #endif
  291.  
  292.